/**
 * Copyright (c) 2008 Trent Hoeppner
 * 
 * This file is part of BillCalc.
 * 
 * BillCalc is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * BillCalc is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with BillCalc.  If not, see <http://www.gnu.org/licenses/>.
 **/

package com.trentech.billcalc;

import java.io.FileNotFoundException;
import java.util.Iterator;

import com.trentech.billcalc.gui.BillCalcFrame;

/**
 * BillCalc is the application launcher class.
 * 
 * rent handling
 *   have a landlord, subletter(s), tenants
 *      can all live there and pay bills (residents)
 *      landlord and subletters maybe do not live there and ignore bills
 *   rent is charged for a period
 *      rent bill generated automatically?
 *          requires knowing today's date
 *      rent bill manually entered
 *          requires remembering each tenant's due date
 *   have a deposit
 *   damage cost on leaving, breaking the lease (penalty for breaking)
 *   can transfer lease
 *   have lease length
 *   
 * vacation
 *   don't pay bills that depend on usage
 *   pay bills that are fixed-cost
 * 
 * @author Trent Hoeppner
 */
public class BillCalc {
    
    /**
     * FinanceManager for this.
     */
    private FinanceManager manager = new FinanceManager();
    
    
    /**
     * Constructor for BillCalc.
     */
    private BillCalc() {
        // do nothing
    }
    
    
    /**
     * Loads the events and processes them.
     */
    private void loadData() {
        try {
        	manager.loadEvents();
            manager.processEvents();
        }
        catch (FileNotFoundException e) {
            System.out.println("Events file not found.  Will create one on first save.");
        }
    }


    /**
     * Writes a report to stdout that contains the debts each resident has 
     * with every other resident. 
     */
    private void reportDebts() {
        Iterator<Resident> residentIterator = manager.getResidents().iterator();
        while (residentIterator.hasNext()) {
            Resident resident = residentIterator.next();
            resident.report(manager);
        }
    }
    
    
    /**
     * Entry point for the application.
     * 
     * @param   args    command line arguments.  Ignored.
     */
    public static void main(String[] args) {
    	BillCalc calc = new BillCalc();
        calc.loadData();
        calc.reportDebts();
        new BillCalcFrame(calc.manager);
    }
}
